package org.yanfengying.utils.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.yanfengying.utils.mapper.BastMapper;
import org.yanfengying.utils.query.BastQuery;
import org.yanfengying.utils.service.IBastServer;
import org.yanfengying.utils.PageList;

import java.io.Serializable;
import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BastServerImpl<T> implements IBastServer<T> {
    @Autowired
    private BastMapper<T> bastMapper;

    @Override
    public List<T> loadAll() {
        List<T> basts = bastMapper.loadAll();

        return basts;
    }

    @Override
    @Transactional
    public void insert(T t) {

        bastMapper.insert(t);

    }

    @Override
    @Transactional
    public void delete(Serializable id) {
        bastMapper.delete(id);

    }

    @Override
    public T loadById(Serializable id) {
        return bastMapper.loadById(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        bastMapper.update(t);

    }


    @Override
    public PageList pageList(BastQuery query) {
        //先查询总条数
        Integer totals = bastMapper.totals(query);
        if (totals < 1) {
            return new PageList();
        }
        List<T> t = bastMapper.pageList(query);
        return new PageList(totals, t);
    }
}

